<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class pengiriman_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insertpemesanan($data){
		$this->db->insert('pengiriman',$data);
	}
	function getidpesan(){
	$query = $this->db->query("select max(id_pengiriman) as id_pengiriman from pengiriman");
	return $query;
	
	}
	
	function descbarang($id_barang){
	$query = $this->db->query("select *  from barang where id_barang=".$id_barang."");
	return $query;
	
	}
	
	function inserttransaksi($data){
		$this->db->insert('transaksi',$data);
	}
	
	function insertpenjualan($data){
		$this->db->insert('penjualan',$data);
	}
	
	
	
	// mendapatkan master barang
	
	function get_data_barang(){
		//Select table name
		$this->db->select("*");
		$this->db->from('barang');
		$query = $this->db->get();
		return $query;
		
		
	}
	
	// get master konsumen
	function get_data_konsumen(){
		//Select table name
		$this->db->select("*");
		$this->db->from('konsumen');
		$query = $this->db->get();
		return $query;
		
		
	}
	
	//list flexy
	function get_data_m_pengiriman(){
		$this->db->select('*,pengiriman.status as status_pengiriman,
		pengiriman.tanggal as tanggal_pengiriman,konsumen.nama as nama_konsumen,
		konsumen.alamat as alamat_konsumen, karyawan.nama as nama_karyawan,
		barang.nama as nama_barang');
        $this->db->from('pengiriman,pesanan,konsumen,karyawan,barang');
	    $this->db->where('pengiriman.nomer_pesanan`=`pesanan.nomer_pesanan');
		$this->db->where('pengiriman.karyawan`=`karyawan.id_karyawan');
		$this->db->where('pesanan.no_konsumen`=`konsumen.id_konsumen');
		$this->db->where('pesanan.id_barang`=`barang.id_barang');
		
		$query = $this->db->get();
        return $query;
		
	}
	
	
	
	
	function delete($id){
		$this->db->where('id_pengiriman', $id);
		$this->db->delete('m_pengiriman');
	}
	
	function selectone($id){
		$query=$this->db->query("select * from pengiriman where id_pengiriman=".$id."");
		
		return $query;
	}
	
	//mendapatkan masksimal id penjualan
	
	function maksid(){
		$query=$this->db->query("select maz(id_penjualan) as maksid from penjualan");
		
		return $query;
	}
	
	function update($data,$id ){
		$this->db->where('id_pengiriman',$id);
		$this->db->update('pengiriman',$data);
	}
        
	function get_m_pengiriman(){
		$this->db->select("*");
		$this->db->from('m_pengiriman');
		$this->db->where("STATUS > 0 ");
		$query = $this->db->get();
		return $query;
	}
	
	
}

?>